<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//测试控制器
class IndexController extends Controller{
	//构造函数
	public function __init(){
	}
	
    //动作
    public function index(){
        //一楼--手机
            //获得手机的cid
        $phone = Db::table('category')->where("cname = '手机'")->first();
        $cid = $phone['cid'];
            //实例化分类表和商品表
        $cateModel = new \Admin\Model\Category;
        $goodsModel = new \Admin\Model\Goods;
            //获取所有的数据
        $data = $goodsModel->join('category','category_cid','=','cid')->get();
            //获得所有的子集
        $cids = $cateModel->getSon($data,$cid);
        $cids = implode(',',$cids);
            //获取第一的手机
        $one = $goodsModel->orderBy("click",'DESC')->where("category_cid IN ($cids)")->limit(1)->first();
        $one['cname'] = '手机';
            //获取最热的前7个手机
        $one_small = $goodsModel->orderBy("click",'DESC')->where("category_cid IN ($cids)")->limit(1,6)->get();
        View::with('one',$one);
        View::with('ones',$one_small);
        //热卖手机
        $dataAll = Db::table("goods")->orderBy("click",'DESC')->limit(4)->get();
        View::with('dataAll',$dataAll);
        //2楼
            //获得基础配件cid
        $pei = Db::table('category')->where("cname = '基础配件'")->first();
        $pcid = $pei['cid'];
            //获得所有的子集
        $pcids = $cateModel->getSon($data,$pcid);
        $pcids = implode(',',$pcids);
        $two['cname'] = '基础配件'; 
            //获取热卖的配件
        $two_small = $goodsModel->orderBy("click",'DESC')->where("category_cid IN ($pcids)")->get();
        View::with('twos',$two_small);
        View::with('two',$two);
        //3楼
        //获得必备配件cid
        $bi = Db::table('category')->where("cname = '必备配件'")->first();
        $bcid = $bi['cid'];
            //获得所有的子集
        $bcids = $cateModel->getSon($data,$bcid);
        $bcids = implode(',',$bcids);
        $three['cname'] = '必备配件'; 
            //获取热卖的配件
        $three_small = $goodsModel->orderBy("click",'DESC')->where("category_cid IN ($bcids)")->get();
        View::with('threes',$three_small);
        View::with('three',$three);
        //4楼
        //获得平板&穿戴cid
        $pci = Db::table('category')->where("cname = '平板 & 穿戴'")->first();
        $pcid = $pci['cid'];
            //获得所有的子集
        $pcids = $cateModel->getSon($data,$pcid);
        $pcids = implode(',',$pcids);
        $four['cname'] = '平板 & 穿戴'; 
            //获取热卖的配件
        $four_small = $goodsModel->orderBy("click",'DESC')->where("category_cid IN ($pcids)")->get();
        View::with('fours',$four_small);
        View::with('four',$four);
        View::make();
    }

	
}
